<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app"></div>

  <script>

    var cache = {
      add(key, val) {
        if (localStorage) {
          localStorage.setItem(key, val)
        } else {
          //...
          //document.cookie=""
        }
      }
    }

    var myplugin = {
      install(v) {
        v.prototype.$cache = cache;
      }
    }

    Vue.use(myplugin);


    var vm = new Vue({
      el: "#app",
      mounted() {
        this.$cache.add('username', 'hanye')
      }
    })
  </script>

</body>

</html>